package com.qk.management.controller;

import com.qk.common.PageResult;
import com.qk.common.Result;
import com.qk.common.constant.ClueStatusConstants;
import com.qk.domain.clue.ClueDO;
import com.qk.domain.clue.CluePoolDO;
import com.qk.dto.clue.*;
import com.qk.entity.Clue;
import com.qk.management.aop.anno.LogAnno;
import com.qk.management.service.ClueService;
import com.qk.vo.clue.ClueVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDateTime;

/**
 * @Author: ZgYn
 * @Date 2025/10/13 20:04
 * @name：ClueController
 */
@RestController
@RequestMapping("/clues")
public class ClueController {
    @Autowired
    private ClueService clueService;

    @GetMapping
    public Result clueList(ClueListDTO dto) {
        PageResult<ClueDO> pageResult = clueService.clueListMp(dto);
//        PageResult<ClueDO> pageResult = clueService.clueList(dto);
        return Result.success(pageResult);
    }

    @LogAnno
    @PostMapping
    public Result addClue(@RequestBody ClueDTO clueDTO) {
        clueService.save(clueDTO);
        return Result.success();
    }

    @LogAnno
    @PutMapping("/assign/{clueId}/{userId}")
    public Result updateClue(@PathVariable Integer clueId, @PathVariable Integer userId) {
        clueService.updateById(Clue.builder()
                .id(clueId)
                .userId(userId)
                .updateTime(LocalDateTime.now())
                .status(ClueStatusConstants.FOLLOW_UP)
                .build());
        return Result.success();
    }

    @GetMapping("/{clueId}")
    public Result getClue(@PathVariable Integer clueId) {
        ClueVO clueVO = clueService.getClueById(clueId);
        return Result.success(clueVO);
    }

    @LogAnno
    @PutMapping
    public Result updateClue(@RequestBody UpdateClueInfoDTO updateClueInfoDTO) {
        clueService.updateClue(updateClueInfoDTO);
        return Result.success();
    }

    @LogAnno
    @PutMapping("/toBusiness/{id}")
    public Result toBusiness(@PathVariable Integer id) {
        clueService.toBusiness(id);
        return Result.success();
    }

    @LogAnno
    @PutMapping("/false/{id}")
    public Result falseClue(@PathVariable Integer id, @RequestBody FakeClueDTO dto) {
        clueService.fakeClue(id, dto);
        return Result.success();
    }

    @GetMapping("/pool")
    public Result cluePool(CluePoolDTO dto) {
        PageResult<CluePoolDO> pageResult = clueService.cluePoolList(dto);
        return Result.success(pageResult);
    }
}
